﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PPAP.Model;
using PPAP.BO;
using System.Data;

namespace PPAP.Web.Todolist
{
    public partial class SampleCardWeb : PageBase
    {
        public string RID { get; set; }
        public string SID { get; set; }
        public string his { get; set; }
        public string status { get; set; }
        PPARBO bo = new PPARBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["RID"] != null&&Request.QueryString["SID"]!=null)
                {
                    RID = Request.QueryString["RID"].ToString();
                    SID = Request.QueryString["SID"].ToString();
                    if (Request.QueryString["status"] != null)
                    {
                        status = Request.QueryString["status"].ToString();
                    }
                    else
                    {
                        status = "0";
                    }
                    if (Request.QueryString["his"] != null)
                    {
                        his = Request.QueryString["his"].ToString();
                        btnBack.Visible = false;
                    }
                    else
                    {
                        his = "0";
                    }
                    DataSet ds = bo.GetListForPPARid(RID);
                    DataRow dr = null;
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        dr = ds.Tables[0].Rows[0];
                        lblColor.Text = dr["color"].ToString();
                        lblPartName.Text = dr["bdntpartname"].ToString();
                        lblPartNo.Text = dr["bdntpartno"].ToString();
                        lblPPARdate.Text = dr["ppardate"].ToString() == "" ? "" : DateTime.Parse(dr["ppardate"].ToString()).ToString("yyyy-MM-dd");
                        LblPPARNo.Text = dr["pparno"].ToString();
                        lblRevisionNo.Text = dr["bdntrevisionno"].ToString();
                        lblRevisionStatus.Text = dr["bdntrevisionstatus"].ToString();
                        lblStatus.Text = ShowAuditStatus(dr["status"].ToString());
                        lblSupplierCode.Text = dr["suppliercode"].ToString();
                        lblSupplierName.Text = dr["suppliername"].ToString();
                        lbContactPerson.Text = dr["firstname"].ToString() == "" ? "" : dr["firstname"].ToString() + "." + dr["name"].ToString();
                        lblPersonInformation.Text = dr["email"].ToString() == "" ? "" : dr["email"].ToString() + "/" + dr["telephone"].ToString();
                    }
                }
            }
        }

        public string ShowAuditStatus(string Status)
        {
            string result = "";
            result = "<span style='color:red'>已提交</span>";

            switch (Status.ToLower())
            {
                case "0":
                    result = "<span style='color:blue'></span>";
                    break;
                case "1":
                    result = "<span style='color:red'>PPAR created</span>";
                    break;
                case "2":
                    result = "<span style='color:red'>PPAR submitted</span>";
                    break;
                case "3":
                    result = "<span style='color:red'>Ready for sampling</span>";
                    break;
                case "4":
                    result = "<span style='color:red'>not ready for sampling</span>";
                    break;
                case "5":
                    result = "<span style='color:red'>PPAR circulating</span>";
                    break;
                case "6":
                    result = "<span style='color:blue'>PPAR released</span>";
                    break;
                case "7":
                    result = "<span style='color:blue'>PPAR decided</span>";
                    break;

                default:
                    result = "<span style='color:red'></span>";
                    break;
            }
            //}
            return result;
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["status"] != null)
                Response.Redirect("Approval.aspx");
            else
            Response.Redirect("SampleCard.aspx");
        }

    }
}